﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

// T.R.A.C.
// Main Author: Morgan Davis
// Additional Authors:
// Date: 10/20/2013

namespace TRAC_Demo
{
    public partial class FormEmployeeList : Form
    {
        #region [ Fields ]

        public string returnEmployee { get { return comboEmployees.Text; } } //used to return selected employee back to calling form
        TRACobjectsDataContext DB = new TRACobjectsDataContext();

        #endregion

        #region [ Constructors ]

        public FormEmployeeList() //gathers all employees in the table and sorts by last name in alphabetical order
        {
            InitializeComponent();
            this.BackColor = CurrentUser.UserColor;
            this.ControlBox = false;
            var employeeQuery = from emp in DB.Employees orderby emp.lName select emp;
            foreach (var emp in employeeQuery)
            {
                comboEmployees.Items.Add(emp.EmployeeID.ToString().PadRight(5)
                    + ": " + emp.lName + ", " + emp.fName);
            }
        }

        #endregion

        #region [ Events ]

        public FormEmployeeList(bool orderBy) //overloaded method to allow sorting by employee number rather than last name
        {
            InitializeComponent();
            this.ControlBox = false;
            var employeeQuery = from emp in DB.Employees select emp;
            foreach (var emp in employeeQuery)
            {
                comboEmployees.Items.Add(emp.EmployeeID.ToString().PadRight(5)
                    + ": " + emp.lName + ", " + emp.fName);
            }
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            if (comboEmployees.Text == "")
                this.DialogResult = DialogResult.Cancel; // do not allow return of 'OK' without making a selection
            else
                this.DialogResult = DialogResult.OK;
        }

        private void btnCancel_Click(object sender, EventArgs e) //closes the form and returns 'CANCEL'
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        #endregion
    }
}
